<?php
/*
	[Destoon B2B System] Copyright (c) 2008-2015 www.destoon.com
	This is NOT a freeware, use is subject to license.txt
*/

require 'common.inc.php';
if($readtype<>$checkread) appexit('非法获取信息');
switch($action) {
	case 'selllist':
	     $condition = "status=3 and groupid>5";
	    $r = $db->get_one("SELECT COUNT(*) AS num FROM {$DT_PRE}sell_5 WHERE $condition");
	    $items = $r['num'];
		if($_GET['pagesize']) $pagesize = $_GET['pagesize'];
	    $pages = mobile_pages($items, $page, $pagesize);
	    $lists = array();
	    if($items) {
		$result = $db->query("SELECT itemid,title,username,company,groupid,thumb,hits,edittime FROM {$DT_PRE}sell_5 WHERE $condition ORDER BY edittime desc LIMIT 8");
		while($r = $db->fetch_array($result)) {
			$CAT = get_cat($r['catid']);
	        $r['headname'] = $CAT['catname'];
			$r['commentCount'] = get_numcomment('5',$r['itemid']);
			$r['company'] = $r['company'];
			$r['title'] = dsubstr($r['title'],30);
			$r['adddate'] = timetodate($r['addtime'], 5);
			$r['editdate'] = timetodate($r['edittime'], 5);
			$lists[] = $r;
		}
	}
	$totalCount = $items;
	$totalPages = ceil($items/$pagesize);
	$datalist = array('data' => $lists,'totalCount' => $totalCount,'totalPages' => $totalPages);
	//echo $items;
	exit(json_encode($datalist));
	break;
	case 'citylist':
		$result = $db->query("SELECT areaid,areaname FROM {$DT_PRE}area WHERE parentid=0 ORDER BY listorder,areaid ASC");
			while($r = $db->fetch_array($result)) {
				$r['areaname'] = $r['areaname'];
				$lists[] = $r;
			}
		appjson($lists);
	break;
	case 'typelist':
	$moduleid = $moduleid;
		$result = $db->query("SELECT catid,catname FROM {$DT_PRE}category WHERE parentid=0 and moduleid='$moduleid' ORDER BY listorder,catid ASC");
			while($r = $db->fetch_array($result)) {
				$r['catname'] = $r['catname'];
				$lists[] = $r;
			}
		appjson($lists);
	break;
	default:
		$r = $db->get_one("SELECT COUNT(*) AS num FROM {$DT_PRE}qiandao WHERE addtime>$DT_TIME-86400");
		$items = $r['num'];
		//echo $_username;
		$condition = "username='$_username'";
		$r = $db->get_one("SELECT * FROM {$DT_PRE}qiandao WHERE $condition ORDER BY itemid DESC LIMIT 1");
		$today = str_replace('-','',timetodate($DT_TIME, 0));
		$qdday = str_replace('-','',timetodate($r['addtime'], 0));
		if($r && $qdday==$today){
		$signed = 1;
		}
	break;
}
if(DT_CHARSET != 'UTF-8') toutf8();
?>